package com.jwaoo.chat.session.actions;

import com.dx.as.listener.IImagePickListener;
import com.jwaoo.chat.ChatConstants;
import com.jwaoo.chat.Message;
import com.jwaoo.chat.R;
import com.jwaoo.chat.attachment.FileAttachment;
import com.jwaoo.chat.bitmap.BitmapDecoder;
import com.jwaoo.chat.data.db.MessageHandler;
import java.io.File;

/**
 * Created by hzxuwen on 2015/6/12.
 */
public class ImageAction extends PickImageAction {
    private IImagePickListener listener;
    public ImageAction() {
        super(R.drawable.dialogue_more_album_btn, R.string.input_panel_photo, true);
    }

    public ImageAction(IImagePickListener listener){
        this();
        this.listener = listener;
    }

    @Override
    protected void onPicked(File file,int snap) {
        if (listener != null){
            this.listener.onPick(file);
            return;
        }
        FileAttachment fileAttachment = new FileAttachment();
        fileAttachment.setPath(file.getAbsolutePath());
        int bound[] = BitmapDecoder.decodeBound(file);
        fileAttachment.setWidth(bound[0]);
        fileAttachment.setHeight(bound[1]);
        fileAttachment.setAttachstate(ChatConstants.transferring);
        Message message = MessageHandler.getInstace(getContainer().activity.getApplicationContext()).createMessage(ChatConstants.image,getContainer().account,fileAttachment);
        message.setSnap(snap);
        sendMessage(message);
    }
}

